<?php

include('../../include/functions.inc.php');
include('../../include/inputbuilder.inc.php');

if (!isEmpty(getParam('operation'))) {
    switch (getParam('operation')) {
        case 's':
            save($db);
            break;
        case 'u':
            update($db);
            break;
        case 'd':
            delete($db);
            break;
    }
}

function save($db) {
    $db->query_insert('cllg_entity', array(
        'NAME' => sqlValue(getParam('NAME'), 'text'),
        'LONG_DESCRIPCION' => sqlValue(getParam('LONG_DESCRIPCION'), 'text'),
        'STATUS' => sqlValue(getParam('STATUS'), 'int'),
        'CREATED_BY' => sqlValue(getParam('CREATED_BY'), 'date'),
        'CREATED' => sqlValue(getParam('CREATED'), 'date')));
    echo 'SAVED';
}

function update($db) {
    $db->query_update('cllg_entity', array(
        'NAME' => sqlValue(getParam('NAME'), 'text'),
        'LONG_DESCRIPCION' => sqlValue(getParam('LONG_DESCRIPCION'), 'text'),
        'STATUS' => sqlValue(getParam('STATUS'), 'int')), 'ID=' . sqlValue(getParam('ID'), 'int'));
    echo 'UPDATED';
}

function delete($db) {
    $db->query_delete('cllg_entity', 'ID=' . sqlValue(getParam('ID'), 'int'));
    echo 'DELETED';
}

?>